@tool
class_name ControllerCommand_AreaDetector_SetActive
extends ControllerCommand

#region 属性
@export var detector_id: int
@export var is_active: bool
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
#endregion
#region 公共方法
func activate(controller: ControllerComponent, command_dict_by_tag: Dictionary) -> bool:
	if not super(controller,command_dict_by_tag):
		return false
	var combat_component = controller.get_entity().get_component(CombatComponent)
	if combat_component:
		var res = false
		for commands in command_dict_by_tag.values():
			for command in commands:
				res |= command.is_active
		var detector: HitBoxAreaDetector = combat_component.get_hit_box().get_detector(detector_id)
		if detector:
			detector.set_active(res)
	return true
func deactivate(controller: ControllerComponent, command_dict_by_tag: Dictionary):
	var combat_component = controller.get_entity().get_component(CombatComponent)
	if combat_component:
		var res = false
		for commands in command_dict_by_tag.values():
			for command in commands:
				res |= command.is_active
		var detector: HitBoxAreaDetector = combat_component.get_hit_box().get_detector(detector_id)
		if detector:
			detector.set_active(res)  # Ensure the detector is deactivated if necessary
	super(controller, command_dict_by_tag)
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _init() -> void:
	if Engine.is_editor_hint():
		resource_local_to_scene = true
#endregion
